﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using pay.DAL;

    ///<summary> 
    ///Module ID：
    ///Depiction： Web_video_img对应下载模块中的持久化操作
    ///Author：张叶 
    ///Create Date： 2011-02-18 
    ///</summary>
public class Web_video_imgDAL
{
    /// <summary>
    /// Web_video_img对象的添加方法
    /// </summary>
    /// <param name="t">Web_video_img实体对象</param>
    /// <returns>数据库影响行数</returns>
    public int Add(Web_video_img t)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.VarChar, t.Id);
            tool.AddSqlParameter("v_img", SqlDbType.VarChar, 200, t.V_img);
            tool.AddSqlParameter("v_id", SqlDbType.Int, 4, t.V_id);
            tool.AddSqlParameter("v_classid", SqlDbType.Int, 4, t.V_classid);
            tool.AddSqlParameter("flag", SqlDbType.VarChar, 6, "add");
            return Emoney.DataAccess.SqlHelper.ExecuteNonQuery(DBConn.Con_emweb_new, CommandType.StoredProcedure, "Web_video_img_Add_Update", tool.GetSqlParameters());
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_video_imgDAL.Add(Web_video_img t)", LogYuMin.LogStates.ERROR, ex);
          
            
            return 0;
        }
    }

    /// <summary>
    /// 更新Web_video_img实体
    /// </summary>
    /// <param name="t">要更新的Web_video_img对象</param>
    /// <returns>数据库影响行数</returns>
    public int Update(Web_video_img t)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.VarChar, t.Id);
            tool.AddSqlParameter("v_img", SqlDbType.VarChar, 200, t.V_img);
            tool.AddSqlParameter("v_id", SqlDbType.Int, 4, t.V_id);
            tool.AddSqlParameter("v_classid", SqlDbType.Int, 4, t.V_classid);
            tool.AddSqlParameter("flag", SqlDbType.VarChar, 6, "update");
            return Emoney.DataAccess.SqlHelper.ExecuteNonQuery(DBConn.Con_emweb_new, CommandType.StoredProcedure, "Web_video_img_Add_Update", tool.GetSqlParameters());
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_video_imgDAL.Update", LogYuMin.LogStates.ERROR, ex);
            return 0;
        }
    }

    /// <summary>
    /// 删除Web_video_img对象
    /// </summary>
    /// <param name="t">要删除的Web_video_img对象</param>
    /// <returns>数据库影响的行数</returns>
    public int Delete(Web_video_img t)
    {
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.VarChar, t.Id);
            return Emoney.DataAccess.SqlHelper.ExecuteNonQuery(DBConn.Con_emweb_new, CommandType.StoredProcedure, "Web_video_img_DeleteById", tool.GetSqlParameters());
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_video_imgDAL.Delete", LogYuMin.LogStates.ERROR, ex);
            return 0;
        }
    }

    /// <summary>
    /// 根据主键得到一个Web_video_img对象
    /// </summary>
    /// <param name="id">vid</param>
    ///  <param name="classid">classid</param>
    /// <returns>Web_video_img对象</returns>
    public Web_video_img GetElementById(object id,object classid)
    {
        SqlConnection con = null;
        SqlDataReader reader = null;
        try
        {
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.Int, 4, id);
            tool.AddSqlParameter("classid", SqlDbType.Int, 4, classid);
            reader = Emoney.DataAccess.SqlHelper.ExecuteReader(DBConn.Con_emweb_new, CommandType.StoredProcedure, "[web_video_img_GetElementByvidAndClassid]", tool.GetSqlParameters());
            Web_video_img m = null;
            if (reader.Read())
            {
                m = new Web_video_img();
                m.Id = Tools.GetString(reader["id"]);
                m.V_img = Tools.GetString(reader["v_img"]);
                m.V_id = Tools.GetInt(reader["v_id"]);
                m.V_classid = Tools.GetInt(reader["v_classid"]);
            }
            return m;
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_video_imgDAL.GetElementById(object id)", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
            if (con != null)
            {
                con.Close();
            }
        }
    }
    /// <summary>
    /// 得到所有的视频图片
    /// </summary>
    /// <returns></returns>
    public List<Web_video_img> GetAll()
    {
        try
        {
            DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(DBConn.Con_emweb_new, System.Data.CommandType.StoredProcedure, "Web_video_img_GetAll", null);
            List<Web_video_img> lst = new List<Web_video_img>();
            DataTable tb = ds.Tables[0];
            foreach (DataRow reader in tb.Rows)
            {
                Web_video_img m = new Web_video_img();
                m.Id = Tools.GetString(reader["id"]);
                m.V_img = Tools.GetString(reader["v_img"]);
                m.V_id = Tools.GetInt(reader["v_id"]);
                m.V_classid = Tools.GetInt(reader["v_classid"]);
                lst.Add(m);
            }
            return lst;
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.Log).Write(GetType(), "Web_video_imgDAL.GetAll", LogYuMin.LogStates.ERROR, ex);
            return null;
        }
    }
}
